<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="form/show/index.css">
    <link rel="stylesheet" href="form/show/FormMaking.css">
</head>
<body>
<div id="app">
    <fm-generate-form
            :data="jsonData"
            :remote="remoteFuncs"
            :value="editData"
            ref="generateForm"
    >
    </fm-generate-form>
    <el-button type="primary" @click="handleSubmit">提交</el-button>
</div>
<script src="form/show/vue.js"></script>
<script src="form/show/index.js"></script>
<script src="form/show/FormMaking.umd.js"></script>
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script>

    (function($){
        $.getUrlParam = function(name)
        {
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r!=null) return unescape(r[2]); return null;
        }
    })(jQuery);

    $(function() {
        //alert(window.location.href);
        //alert($.getUrlParam('taskId'));
        var taskId = $.getUrlParam('taskId')
        $.ajax({
            type: 'POST',
            contentType: "application/json;charset=UTF-8",
            url: '/process/runor/'+taskId,
            dataType: 'json',
            data:'{"dealType":"0","dealReason":"eeeee"}',
            success: function(data){
                var obj = eval(data);
               //alert(data[0].formKey);
               // alert(data[0].taskId);
                 var formKey = data[0].formKey;
                 var taskId = data[0].taskId;

                $.ajax({
                    type: 'POST',
                    url: '/sys-forms/find?id='+formKey,
                    dataType: 'json',
                    success: function(data){
                        var jsonstr = eval(eval(data).data).formValue;
                     //   alert(jsonstr)

                        new Vue({
                            el: '#app',
                            data: {
                                jsonData: JSON.parse(jsonstr),
                                editData: {},
                                remoteFuncs: {

                                }
                            },
                            methods: {
                                handleSubmit () {
                                    this.$refs.generateForm.getData().then(data => {

                                        $.ajax({
                                            type: 'POST',
                                            contentType: "application/json;charset=UTF-8",
                                            url: '/runtime/tasks/do/'+taskId,
                                            dataType: 'json',
                                            data:JSON.stringify(data),
                                            //data:'{"dealType":"0","dealReason":"eeeee"}',
                                            success: function(data){
                                                layer.msg('提交成功！!',{icon:1,time:1000});
                                            },
                                            error:function(data) {
                                                console.log(data.msg);
                                            },
                                        });
                                    }).catch(e => {
                                        // data check failed
                                    })
                                }
                            }
                        })





                    }
                });


            },
            error:function(data) {
                // console.log(data.msg);
            },
        });
    });

</script>
</body>
</html>
